In [1]:
# データのロード
data(iris)
In [2]:
# データの確認
str(iris)
'data.frame':	150 obs. of  5 variables:
 $ Sepal.Length: num  5.1 4.9 4.7 4.6 5 5.4 4.6 5 4.4 4.9 ...
 $ Sepal.Width : num  3.5 3 3.2 3.1 3.6 3.9 3.4 3.4 2.9 3.1 ...
 $ Petal.Length: num  1.4 1.4 1.3 1.5 1.4 1.7 1.4 1.5 1.4 1.5 ...
 $ Petal.Width : num  0.2 0.2 0.2 0.2 0.2 0.4 0.3 0.2 0.2 0.1 ...
 $ Species     : Factor w/ 3 levels "setosa","versicolor",..: 1 1 1 1 1 1 1 1 1 1 ...
In [3]:
# 標準偏差
sd(iris$Sepal.Length)
0.828066127977863
In [4]:
# 可視化用にライブラリのインストール
install.packages("ggplot2")
Updating HTML index of packages in '.Library'

Making 'packages.html' ...
 done

In [5]:
# ライブラリパッケージのロード
library(ggplot2)
In [6]:
# 散布図を書く
qplot(data=iris, x=Sepal.Length, y=Sepal.Width, color=Species)
In [8]:
# 回帰直線を追加
qplot(data=iris, x=Sepal.Length, y=Sepal.Width, color=Species) +stat_smooth(method = "lm",fullrange = T, se = T,aes(fill = Species, color=Species),alpha=0.1)
`geom_smooth()` using formula 'y ~ x'

In [9]:
# 3次元プロットのためにライブラリのロード
library(lattice)
In [10]:
# 3次元プロット
cloud(data = iris, Sepal.Length ~ Petal.Length * Petal.Width,  groups = Species)
In [11]:
# ライブラリのロード
install.packages("plotly")
library(plotly)
also installing the dependency ‘crosstalk’


Updating HTML index of packages in '.Library'

Making 'packages.html' ...
 done


Attaching package: ‘plotly’


The following object is masked from ‘package:ggplot2’:

    last_plot


The following object is masked from ‘package:stats’:

    filter


The following object is masked from ‘package:graphics’:

    layout


In [12]:
# 火山のサンプルデータの3次元可視化
plot_ly(z = ~volcano) %>% add_surface()
In [ ]: